package com.iretailer.report.web.business;

import com.iretailer.report.base.BaseAction;
import com.iretailer.report.dto.PageResult;
import com.iretailer.report.dto.QueryOption;
import com.iretailer.report.dto.ReWeather;
import com.iretailer.report.model.Weathers;
import com.iretailer.report.quartz.systemTask.WeatherTask;
import com.iretailer.report.util.RMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Auther: xjw
 * @Date: 2019/1/25 14:46
 * @Description:
 */
@RestController
public class WeatherController extends BaseAction {

    @Autowired
    private WeatherTask weatherTask;

    @RequestMapping("/system/weatherGrid.action")
    public Map<String, Object> weatherGrid(@RequestBody ReWeather reWeather) {
        QueryOption queryOption = modelMapper.map(reWeather, QueryOption.class);
        PageResult<Weathers> findPage = weatherService.gridPage(reWeather.getCityName(), reWeather.getDate(), queryOption);
        return RMap.ok(findPage);
    }

    @RequestMapping("/system/getTodayWeather.action")
    public Map<String, Object> getTodayWeather() {
        weatherTask.execute();
        return RMap.ok();
    }

}
